{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 读取文件"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(13887, 29)\n",
      "(12955, 28)\n"
     ]
    }
   ],
   "source": [
    "#读取文件\n",
    "import pickle\n",
    "\n",
    "with open('./df_train.pkl','rb') as file:\n",
    "    df_train=pickle.load(file)\n",
    "\n",
    "with open('./df_test.pkl','rb') as file:\n",
    "    df_test=pickle.load(file) \n",
    "\n",
    "print(df_train.shape)    \n",
    "print(df_test.shape)#读取完毕了"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>file_id</th>\n",
       "      <th>label</th>\n",
       "      <th>api</th>\n",
       "      <th>tid</th>\n",
       "      <th>index</th>\n",
       "      <th>api_count</th>\n",
       "      <th>api_nunique</th>\n",
       "      <th>api_min</th>\n",
       "      <th>api_max</th>\n",
       "      <th>api_mean</th>\n",
       "      <th>...</th>\n",
       "      <th>tid_std</th>\n",
       "      <th>tid_ptp</th>\n",
       "      <th>index_count</th>\n",
       "      <th>index_nunique</th>\n",
       "      <th>index_min</th>\n",
       "      <th>index_max</th>\n",
       "      <th>index_mean</th>\n",
       "      <th>index_median</th>\n",
       "      <th>index_std</th>\n",
       "      <th>index_ptp</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>5</td>\n",
       "      <td>135</td>\n",
       "      <td>2488</td>\n",
       "      <td>0</td>\n",
       "      <td>6786</td>\n",
       "      <td>116</td>\n",
       "      <td>6</td>\n",
       "      <td>298</td>\n",
       "      <td>171.965223</td>\n",
       "      <td>...</td>\n",
       "      <td>83.881299</td>\n",
       "      <td>324</td>\n",
       "      <td>6786</td>\n",
       "      <td>5001</td>\n",
       "      <td>0</td>\n",
       "      <td>5000</td>\n",
       "      <td>2000.806955</td>\n",
       "      <td>1607.5</td>\n",
       "      <td>1510.694221</td>\n",
       "      <td>5000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6786</th>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>95</td>\n",
       "      <td>2320</td>\n",
       "      <td>0</td>\n",
       "      <td>816</td>\n",
       "      <td>30</td>\n",
       "      <td>89</td>\n",
       "      <td>298</td>\n",
       "      <td>159.696078</td>\n",
       "      <td>...</td>\n",
       "      <td>101.506783</td>\n",
       "      <td>284</td>\n",
       "      <td>816</td>\n",
       "      <td>204</td>\n",
       "      <td>0</td>\n",
       "      <td>203</td>\n",
       "      <td>101.500000</td>\n",
       "      <td>101.5</td>\n",
       "      <td>58.925137</td>\n",
       "      <td>203</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7602</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>151</td>\n",
       "      <td>2208</td>\n",
       "      <td>0</td>\n",
       "      <td>463</td>\n",
       "      <td>42</td>\n",
       "      <td>9</td>\n",
       "      <td>258</td>\n",
       "      <td>164.948164</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0</td>\n",
       "      <td>463</td>\n",
       "      <td>463</td>\n",
       "      <td>0</td>\n",
       "      <td>462</td>\n",
       "      <td>231.000000</td>\n",
       "      <td>231.0</td>\n",
       "      <td>133.800847</td>\n",
       "      <td>462</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8065</th>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>95</td>\n",
       "      <td>2284</td>\n",
       "      <td>0</td>\n",
       "      <td>2046</td>\n",
       "      <td>51</td>\n",
       "      <td>9</td>\n",
       "      <td>257</td>\n",
       "      <td>154.939883</td>\n",
       "      <td>...</td>\n",
       "      <td>150.460506</td>\n",
       "      <td>696</td>\n",
       "      <td>2046</td>\n",
       "      <td>1028</td>\n",
       "      <td>0</td>\n",
       "      <td>1027</td>\n",
       "      <td>511.012219</td>\n",
       "      <td>511.0</td>\n",
       "      <td>295.407885</td>\n",
       "      <td>1027</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10111</th>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "      <td>249</td>\n",
       "      <td>2500</td>\n",
       "      <td>0</td>\n",
       "      <td>10002</td>\n",
       "      <td>65</td>\n",
       "      <td>6</td>\n",
       "      <td>254</td>\n",
       "      <td>201.893421</td>\n",
       "      <td>...</td>\n",
       "      <td>49.556301</td>\n",
       "      <td>176</td>\n",
       "      <td>10002</td>\n",
       "      <td>5001</td>\n",
       "      <td>0</td>\n",
       "      <td>5000</td>\n",
       "      <td>2500.000000</td>\n",
       "      <td>2500.0</td>\n",
       "      <td>1443.736493</td>\n",
       "      <td>5000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>89620181</th>\n",
       "      <td>13883</td>\n",
       "      <td>2</td>\n",
       "      <td>95</td>\n",
       "      <td>100</td>\n",
       "      <td>0</td>\n",
       "      <td>178221</td>\n",
       "      <td>71</td>\n",
       "      <td>6</td>\n",
       "      <td>279</td>\n",
       "      <td>156.643100</td>\n",
       "      <td>...</td>\n",
       "      <td>1405.045515</td>\n",
       "      <td>6468</td>\n",
       "      <td>178221</td>\n",
       "      <td>5001</td>\n",
       "      <td>0</td>\n",
       "      <td>5000</td>\n",
       "      <td>401.480987</td>\n",
       "      <td>47.0</td>\n",
       "      <td>1008.636040</td>\n",
       "      <td>5000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>89798402</th>\n",
       "      <td>13884</td>\n",
       "      <td>5</td>\n",
       "      <td>95</td>\n",
       "      <td>2592</td>\n",
       "      <td>0</td>\n",
       "      <td>1319</td>\n",
       "      <td>39</td>\n",
       "      <td>6</td>\n",
       "      <td>279</td>\n",
       "      <td>163.025019</td>\n",
       "      <td>...</td>\n",
       "      <td>4.295386</td>\n",
       "      <td>156</td>\n",
       "      <td>1319</td>\n",
       "      <td>1319</td>\n",
       "      <td>0</td>\n",
       "      <td>1318</td>\n",
       "      <td>659.000000</td>\n",
       "      <td>659.0</td>\n",
       "      <td>380.906813</td>\n",
       "      <td>1318</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>89799721</th>\n",
       "      <td>13885</td>\n",
       "      <td>0</td>\n",
       "      <td>151</td>\n",
       "      <td>2240</td>\n",
       "      <td>0</td>\n",
       "      <td>1033</td>\n",
       "      <td>71</td>\n",
       "      <td>8</td>\n",
       "      <td>259</td>\n",
       "      <td>174.896418</td>\n",
       "      <td>...</td>\n",
       "      <td>33.152020</td>\n",
       "      <td>504</td>\n",
       "      <td>1033</td>\n",
       "      <td>1033</td>\n",
       "      <td>0</td>\n",
       "      <td>1032</td>\n",
       "      <td>516.000000</td>\n",
       "      <td>516.0</td>\n",
       "      <td>298.345717</td>\n",
       "      <td>1032</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>89800754</th>\n",
       "      <td>13886</td>\n",
       "      <td>1</td>\n",
       "      <td>95</td>\n",
       "      <td>2324</td>\n",
       "      <td>0</td>\n",
       "      <td>5316</td>\n",
       "      <td>80</td>\n",
       "      <td>9</td>\n",
       "      <td>281</td>\n",
       "      <td>168.313017</td>\n",
       "      <td>...</td>\n",
       "      <td>154.796790</td>\n",
       "      <td>512</td>\n",
       "      <td>5316</td>\n",
       "      <td>2503</td>\n",
       "      <td>0</td>\n",
       "      <td>2502</td>\n",
       "      <td>1173.050414</td>\n",
       "      <td>1165.5</td>\n",
       "      <td>755.545651</td>\n",
       "      <td>2502</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>89806070</th>\n",
       "      <td>13887</td>\n",
       "      <td>2</td>\n",
       "      <td>135</td>\n",
       "      <td>2336</td>\n",
       "      <td>0</td>\n",
       "      <td>623</td>\n",
       "      <td>37</td>\n",
       "      <td>11</td>\n",
       "      <td>277</td>\n",
       "      <td>139.784912</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0</td>\n",
       "      <td>623</td>\n",
       "      <td>623</td>\n",
       "      <td>0</td>\n",
       "      <td>622</td>\n",
       "      <td>311.000000</td>\n",
       "      <td>311.0</td>\n",
       "      <td>179.988889</td>\n",
       "      <td>622</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>13887 rows × 29 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "          file_id  label  api   tid  index  api_count  api_nunique  api_min  \\\n",
       "0               1      5  135  2488      0       6786          116        6   \n",
       "6786            2      2   95  2320      0        816           30       89   \n",
       "7602            3      0  151  2208      0        463           42        9   \n",
       "8065            4      0   95  2284      0       2046           51        9   \n",
       "10111           5      0  249  2500      0      10002           65        6   \n",
       "...           ...    ...  ...   ...    ...        ...          ...      ...   \n",
       "89620181    13883      2   95   100      0     178221           71        6   \n",
       "89798402    13884      5   95  2592      0       1319           39        6   \n",
       "89799721    13885      0  151  2240      0       1033           71        8   \n",
       "89800754    13886      1   95  2324      0       5316           80        9   \n",
       "89806070    13887      2  135  2336      0        623           37       11   \n",
       "\n",
       "          api_max    api_mean  ...      tid_std  tid_ptp  index_count  \\\n",
       "0             298  171.965223  ...    83.881299      324         6786   \n",
       "6786          298  159.696078  ...   101.506783      284          816   \n",
       "7602          258  164.948164  ...     0.000000        0          463   \n",
       "8065          257  154.939883  ...   150.460506      696         2046   \n",
       "10111         254  201.893421  ...    49.556301      176        10002   \n",
       "...           ...         ...  ...          ...      ...          ...   \n",
       "89620181      279  156.643100  ...  1405.045515     6468       178221   \n",
       "89798402      279  163.025019  ...     4.295386      156         1319   \n",
       "89799721      259  174.896418  ...    33.152020      504         1033   \n",
       "89800754      281  168.313017  ...   154.796790      512         5316   \n",
       "89806070      277  139.784912  ...     0.000000        0          623   \n",
       "\n",
       "          index_nunique  index_min  index_max   index_mean  index_median  \\\n",
       "0                  5001          0       5000  2000.806955        1607.5   \n",
       "6786                204          0        203   101.500000         101.5   \n",
       "7602                463          0        462   231.000000         231.0   \n",
       "8065               1028          0       1027   511.012219         511.0   \n",
       "10111              5001          0       5000  2500.000000        2500.0   \n",
       "...                 ...        ...        ...          ...           ...   \n",
       "89620181           5001          0       5000   401.480987          47.0   \n",
       "89798402           1319          0       1318   659.000000         659.0   \n",
       "89799721           1033          0       1032   516.000000         516.0   \n",
       "89800754           2503          0       2502  1173.050414        1165.5   \n",
       "89806070            623          0        622   311.000000         311.0   \n",
       "\n",
       "            index_std  index_ptp  \n",
       "0         1510.694221       5000  \n",
       "6786        58.925137        203  \n",
       "7602       133.800847        462  \n",
       "8065       295.407885       1027  \n",
       "10111     1443.736493       5000  \n",
       "...               ...        ...  \n",
       "89620181  1008.636040       5000  \n",
       "89798402   380.906813       1318  \n",
       "89799721   298.345717       1032  \n",
       "89800754   755.545651       2502  \n",
       "89806070   179.988889        622  \n",
       "\n",
       "[13887 rows x 29 columns]"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_train"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>file_id</th>\n",
       "      <th>api</th>\n",
       "      <th>tid</th>\n",
       "      <th>index</th>\n",
       "      <th>api_count</th>\n",
       "      <th>api_nunique</th>\n",
       "      <th>api_min</th>\n",
       "      <th>api_max</th>\n",
       "      <th>api_mean</th>\n",
       "      <th>api_median</th>\n",
       "      <th>...</th>\n",
       "      <th>tid_std</th>\n",
       "      <th>tid_ptp</th>\n",
       "      <th>index_count</th>\n",
       "      <th>index_nunique</th>\n",
       "      <th>index_min</th>\n",
       "      <th>index_max</th>\n",
       "      <th>index_mean</th>\n",
       "      <th>index_median</th>\n",
       "      <th>index_std</th>\n",
       "      <th>index_ptp</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>226</td>\n",
       "      <td>2332</td>\n",
       "      <td>0</td>\n",
       "      <td>97</td>\n",
       "      <td>15</td>\n",
       "      <td>13</td>\n",
       "      <td>262</td>\n",
       "      <td>155.989691</td>\n",
       "      <td>152.0</td>\n",
       "      <td>...</td>\n",
       "      <td>57.218548</td>\n",
       "      <td>236</td>\n",
       "      <td>97</td>\n",
       "      <td>31</td>\n",
       "      <td>0</td>\n",
       "      <td>30</td>\n",
       "      <td>14.443299</td>\n",
       "      <td>14.0</td>\n",
       "      <td>9.210466</td>\n",
       "      <td>30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>97</th>\n",
       "      <td>2</td>\n",
       "      <td>226</td>\n",
       "      <td>2472</td>\n",
       "      <td>0</td>\n",
       "      <td>1361</td>\n",
       "      <td>40</td>\n",
       "      <td>6</td>\n",
       "      <td>261</td>\n",
       "      <td>138.025716</td>\n",
       "      <td>138.0</td>\n",
       "      <td>...</td>\n",
       "      <td>104.399149</td>\n",
       "      <td>276</td>\n",
       "      <td>1361</td>\n",
       "      <td>681</td>\n",
       "      <td>0</td>\n",
       "      <td>680</td>\n",
       "      <td>339.750184</td>\n",
       "      <td>340.0</td>\n",
       "      <td>196.515744</td>\n",
       "      <td>680</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1458</th>\n",
       "      <td>3</td>\n",
       "      <td>95</td>\n",
       "      <td>2344</td>\n",
       "      <td>0</td>\n",
       "      <td>16</td>\n",
       "      <td>9</td>\n",
       "      <td>16</td>\n",
       "      <td>257</td>\n",
       "      <td>111.375000</td>\n",
       "      <td>134.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0</td>\n",
       "      <td>16</td>\n",
       "      <td>16</td>\n",
       "      <td>0</td>\n",
       "      <td>15</td>\n",
       "      <td>7.500000</td>\n",
       "      <td>7.5</td>\n",
       "      <td>4.760952</td>\n",
       "      <td>15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1474</th>\n",
       "      <td>4</td>\n",
       "      <td>135</td>\n",
       "      <td>2452</td>\n",
       "      <td>0</td>\n",
       "      <td>193</td>\n",
       "      <td>34</td>\n",
       "      <td>13</td>\n",
       "      <td>262</td>\n",
       "      <td>172.217617</td>\n",
       "      <td>170.0</td>\n",
       "      <td>...</td>\n",
       "      <td>50.951508</td>\n",
       "      <td>132</td>\n",
       "      <td>193</td>\n",
       "      <td>193</td>\n",
       "      <td>0</td>\n",
       "      <td>192</td>\n",
       "      <td>96.000000</td>\n",
       "      <td>96.0</td>\n",
       "      <td>55.858452</td>\n",
       "      <td>192</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1667</th>\n",
       "      <td>5</td>\n",
       "      <td>95</td>\n",
       "      <td>2332</td>\n",
       "      <td>0</td>\n",
       "      <td>803</td>\n",
       "      <td>34</td>\n",
       "      <td>16</td>\n",
       "      <td>261</td>\n",
       "      <td>168.490660</td>\n",
       "      <td>153.0</td>\n",
       "      <td>...</td>\n",
       "      <td>201.826813</td>\n",
       "      <td>448</td>\n",
       "      <td>803</td>\n",
       "      <td>268</td>\n",
       "      <td>0</td>\n",
       "      <td>267</td>\n",
       "      <td>133.333748</td>\n",
       "      <td>133.0</td>\n",
       "      <td>77.317048</td>\n",
       "      <td>267</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>79277890</th>\n",
       "      <td>12951</td>\n",
       "      <td>151</td>\n",
       "      <td>2644</td>\n",
       "      <td>0</td>\n",
       "      <td>289</td>\n",
       "      <td>37</td>\n",
       "      <td>9</td>\n",
       "      <td>269</td>\n",
       "      <td>140.536332</td>\n",
       "      <td>151.0</td>\n",
       "      <td>...</td>\n",
       "      <td>75.402526</td>\n",
       "      <td>336</td>\n",
       "      <td>289</td>\n",
       "      <td>145</td>\n",
       "      <td>0</td>\n",
       "      <td>144</td>\n",
       "      <td>71.750865</td>\n",
       "      <td>72.0</td>\n",
       "      <td>41.786414</td>\n",
       "      <td>144</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>79278179</th>\n",
       "      <td>12952</td>\n",
       "      <td>151</td>\n",
       "      <td>2264</td>\n",
       "      <td>0</td>\n",
       "      <td>112</td>\n",
       "      <td>28</td>\n",
       "      <td>56</td>\n",
       "      <td>261</td>\n",
       "      <td>163.669643</td>\n",
       "      <td>152.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0</td>\n",
       "      <td>112</td>\n",
       "      <td>112</td>\n",
       "      <td>0</td>\n",
       "      <td>111</td>\n",
       "      <td>55.500000</td>\n",
       "      <td>55.5</td>\n",
       "      <td>32.475632</td>\n",
       "      <td>111</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>79278291</th>\n",
       "      <td>12953</td>\n",
       "      <td>135</td>\n",
       "      <td>2324</td>\n",
       "      <td>0</td>\n",
       "      <td>5095</td>\n",
       "      <td>72</td>\n",
       "      <td>6</td>\n",
       "      <td>286</td>\n",
       "      <td>200.063199</td>\n",
       "      <td>214.0</td>\n",
       "      <td>...</td>\n",
       "      <td>196.695730</td>\n",
       "      <td>560</td>\n",
       "      <td>5095</td>\n",
       "      <td>1464</td>\n",
       "      <td>0</td>\n",
       "      <td>1463</td>\n",
       "      <td>538.423749</td>\n",
       "      <td>454.0</td>\n",
       "      <td>393.605016</td>\n",
       "      <td>1463</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>79283386</th>\n",
       "      <td>12954</td>\n",
       "      <td>135</td>\n",
       "      <td>2424</td>\n",
       "      <td>0</td>\n",
       "      <td>2951</td>\n",
       "      <td>65</td>\n",
       "      <td>9</td>\n",
       "      <td>298</td>\n",
       "      <td>191.007794</td>\n",
       "      <td>139.0</td>\n",
       "      <td>...</td>\n",
       "      <td>126.124152</td>\n",
       "      <td>276</td>\n",
       "      <td>2951</td>\n",
       "      <td>1445</td>\n",
       "      <td>0</td>\n",
       "      <td>1444</td>\n",
       "      <td>596.701796</td>\n",
       "      <td>555.0</td>\n",
       "      <td>397.358069</td>\n",
       "      <td>1444</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>79286337</th>\n",
       "      <td>12955</td>\n",
       "      <td>135</td>\n",
       "      <td>2500</td>\n",
       "      <td>0</td>\n",
       "      <td>2038</td>\n",
       "      <td>54</td>\n",
       "      <td>13</td>\n",
       "      <td>284</td>\n",
       "      <td>208.845927</td>\n",
       "      <td>266.0</td>\n",
       "      <td>...</td>\n",
       "      <td>78.912837</td>\n",
       "      <td>240</td>\n",
       "      <td>2038</td>\n",
       "      <td>1451</td>\n",
       "      <td>0</td>\n",
       "      <td>1450</td>\n",
       "      <td>560.742885</td>\n",
       "      <td>431.5</td>\n",
       "      <td>440.983364</td>\n",
       "      <td>1450</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>12955 rows × 28 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "          file_id  api   tid  index  api_count  api_nunique  api_min  api_max  \\\n",
       "0               1  226  2332      0         97           15       13      262   \n",
       "97              2  226  2472      0       1361           40        6      261   \n",
       "1458            3   95  2344      0         16            9       16      257   \n",
       "1474            4  135  2452      0        193           34       13      262   \n",
       "1667            5   95  2332      0        803           34       16      261   \n",
       "...           ...  ...   ...    ...        ...          ...      ...      ...   \n",
       "79277890    12951  151  2644      0        289           37        9      269   \n",
       "79278179    12952  151  2264      0        112           28       56      261   \n",
       "79278291    12953  135  2324      0       5095           72        6      286   \n",
       "79283386    12954  135  2424      0       2951           65        9      298   \n",
       "79286337    12955  135  2500      0       2038           54       13      284   \n",
       "\n",
       "            api_mean  api_median  ...     tid_std  tid_ptp  index_count  \\\n",
       "0         155.989691       152.0  ...   57.218548      236           97   \n",
       "97        138.025716       138.0  ...  104.399149      276         1361   \n",
       "1458      111.375000       134.0  ...    0.000000        0           16   \n",
       "1474      172.217617       170.0  ...   50.951508      132          193   \n",
       "1667      168.490660       153.0  ...  201.826813      448          803   \n",
       "...              ...         ...  ...         ...      ...          ...   \n",
       "79277890  140.536332       151.0  ...   75.402526      336          289   \n",
       "79278179  163.669643       152.0  ...    0.000000        0          112   \n",
       "79278291  200.063199       214.0  ...  196.695730      560         5095   \n",
       "79283386  191.007794       139.0  ...  126.124152      276         2951   \n",
       "79286337  208.845927       266.0  ...   78.912837      240         2038   \n",
       "\n",
       "          index_nunique  index_min  index_max  index_mean  index_median  \\\n",
       "0                    31          0         30   14.443299          14.0   \n",
       "97                  681          0        680  339.750184         340.0   \n",
       "1458                 16          0         15    7.500000           7.5   \n",
       "1474                193          0        192   96.000000          96.0   \n",
       "1667                268          0        267  133.333748         133.0   \n",
       "...                 ...        ...        ...         ...           ...   \n",
       "79277890            145          0        144   71.750865          72.0   \n",
       "79278179            112          0        111   55.500000          55.5   \n",
       "79278291           1464          0       1463  538.423749         454.0   \n",
       "79283386           1445          0       1444  596.701796         555.0   \n",
       "79286337           1451          0       1450  560.742885         431.5   \n",
       "\n",
       "           index_std  index_ptp  \n",
       "0           9.210466         30  \n",
       "97        196.515744        680  \n",
       "1458        4.760952         15  \n",
       "1474       55.858452        192  \n",
       "1667       77.317048        267  \n",
       "...              ...        ...  \n",
       "79277890   41.786414        144  \n",
       "79278179   32.475632        111  \n",
       "79278291  393.605016       1463  \n",
       "79283386  397.358069       1444  \n",
       "79286337  440.983364       1450  \n",
       "\n",
       "[12955 rows x 28 columns]"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_test"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 文件读取进来了 开始建模预测"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "LGBMClassifier(boosting_type='gbdt', class_weight=None, colsample_bytree=1,\n",
       "               importance_type='split', learning_rate=0.005, max_depth=-1,\n",
       "               min_child_samples=3, min_child_weight=0.001, min_split_gain=0.0,\n",
       "               n_estimators=2000, n_jobs=-1, num_leaves=31,\n",
       "               objective='multiclass', random_state=2021, reg_alpha=0.25,\n",
       "               reg_lambda=0.25, silent=True, subsample=1,\n",
       "               subsample_for_bin=200000, subsample_freq=0)"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#使用LightGBM 祖传参数\n",
    "import lightgbm as lgb\n",
    "clf = lgb.LGBMClassifier(\n",
    "            num_leaves=2**5-1, reg_alpha=0.25, reg_lambda=0.25, objective='multiclass',\n",
    "            max_depth=-1, learning_rate=0.005, min_child_samples=3, random_state=2021,\n",
    "            n_estimators=2000, subsample=1, colsample_bytree=1)\n",
    "clf"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "训练完毕\n",
      "CPU times: user 19min 8s, sys: 52.1 s, total: 20min\n",
      "Wall time: 38.2 s\n"
     ]
    }
   ],
   "source": [
    "%%time\n",
    "clf.fit(df_train.drop('label',axis=1),df_train['label'])#训练的时候特征是出去lable以外的数据 标签的只有label\n",
    "print(\"训练完毕\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    4978\n",
       "5    4289\n",
       "7    1487\n",
       "2    1196\n",
       "3     820\n",
       "6     515\n",
       "1     502\n",
       "4     100\n",
       "Name: label, dtype: int64"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#因为label是有8个 所以待会儿预测出来的时候方法用predict_proba得到每个类别的概率就OK了\n",
    "df_train['label'].value_counts()#这里是一个8分类的任务"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1.29909605e-02, 2.97339711e-03, 1.16246386e-01, ...,\n",
       "        1.83853784e-02, 8.72276580e-03, 7.27260036e-01],\n",
       "       [8.75509718e-01, 9.38637189e-04, 5.76710702e-03, ...,\n",
       "        5.39843985e-02, 1.81612459e-02, 3.86443780e-02],\n",
       "       [9.98084893e-01, 3.75487851e-05, 2.17619646e-04, ...,\n",
       "        7.40405189e-04, 1.50884474e-04, 6.83814865e-04],\n",
       "       ...,\n",
       "       [7.35136405e-04, 2.55666091e-04, 1.29494421e-03, ...,\n",
       "        9.73190114e-01, 1.77537208e-02, 6.27093167e-03],\n",
       "       [1.97081231e-03, 2.12985158e-05, 7.65178893e-04, ...,\n",
       "        9.94096075e-01, 3.71521420e-04, 2.38030394e-03],\n",
       "       [9.75722977e-04, 1.24267767e-04, 1.79147617e-03, ...,\n",
       "        9.89291667e-01, 1.04264279e-03, 6.17081464e-03]])"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#预测\n",
    "result=clf.predict_proba(df_test)\n",
    "result#这样不是很好看  来做一下dataframe"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0.01299096 0.0029734  0.11624639 0.11265006 0.00077101 0.01838538\n",
      " 0.00872277 0.72726004] 8 1.0\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "(12955, 8)"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "print(result[0],len(result[0]),sum(result[0]))\n",
    "result.shape#这里是有12955行 8列  每一行 8列之和是为1  表示得到属于每个类别的概率"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#有了这个结果 就可以保存一下csv提交一下 得到一个baseline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>prob0</th>\n",
       "      <th>prob1</th>\n",
       "      <th>prob2</th>\n",
       "      <th>prob3</th>\n",
       "      <th>prob4</th>\n",
       "      <th>prob5</th>\n",
       "      <th>prob6</th>\n",
       "      <th>prob7</th>\n",
       "      <th>file_id</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.012991</td>\n",
       "      <td>0.002973</td>\n",
       "      <td>0.116246</td>\n",
       "      <td>0.112650</td>\n",
       "      <td>0.000771</td>\n",
       "      <td>0.018385</td>\n",
       "      <td>0.008723</td>\n",
       "      <td>0.727260</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0.875510</td>\n",
       "      <td>0.000939</td>\n",
       "      <td>0.005767</td>\n",
       "      <td>0.006461</td>\n",
       "      <td>0.000534</td>\n",
       "      <td>0.053984</td>\n",
       "      <td>0.018161</td>\n",
       "      <td>0.038644</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0.998085</td>\n",
       "      <td>0.000038</td>\n",
       "      <td>0.000218</td>\n",
       "      <td>0.000072</td>\n",
       "      <td>0.000013</td>\n",
       "      <td>0.000740</td>\n",
       "      <td>0.000151</td>\n",
       "      <td>0.000684</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0.045739</td>\n",
       "      <td>0.001098</td>\n",
       "      <td>0.004962</td>\n",
       "      <td>0.198713</td>\n",
       "      <td>0.001311</td>\n",
       "      <td>0.132568</td>\n",
       "      <td>0.026041</td>\n",
       "      <td>0.589569</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0.989740</td>\n",
       "      <td>0.000035</td>\n",
       "      <td>0.001995</td>\n",
       "      <td>0.000887</td>\n",
       "      <td>0.000016</td>\n",
       "      <td>0.005407</td>\n",
       "      <td>0.000468</td>\n",
       "      <td>0.001452</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12950</th>\n",
       "      <td>0.833071</td>\n",
       "      <td>0.003057</td>\n",
       "      <td>0.014412</td>\n",
       "      <td>0.003555</td>\n",
       "      <td>0.000654</td>\n",
       "      <td>0.034868</td>\n",
       "      <td>0.003584</td>\n",
       "      <td>0.106798</td>\n",
       "      <td>12951</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12951</th>\n",
       "      <td>0.946363</td>\n",
       "      <td>0.000961</td>\n",
       "      <td>0.002724</td>\n",
       "      <td>0.002242</td>\n",
       "      <td>0.013856</td>\n",
       "      <td>0.023608</td>\n",
       "      <td>0.002090</td>\n",
       "      <td>0.008157</td>\n",
       "      <td>12952</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12952</th>\n",
       "      <td>0.000735</td>\n",
       "      <td>0.000256</td>\n",
       "      <td>0.001295</td>\n",
       "      <td>0.000469</td>\n",
       "      <td>0.000031</td>\n",
       "      <td>0.973190</td>\n",
       "      <td>0.017754</td>\n",
       "      <td>0.006271</td>\n",
       "      <td>12953</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12953</th>\n",
       "      <td>0.001971</td>\n",
       "      <td>0.000021</td>\n",
       "      <td>0.000765</td>\n",
       "      <td>0.000369</td>\n",
       "      <td>0.000025</td>\n",
       "      <td>0.994096</td>\n",
       "      <td>0.000372</td>\n",
       "      <td>0.002380</td>\n",
       "      <td>12954</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12954</th>\n",
       "      <td>0.000976</td>\n",
       "      <td>0.000124</td>\n",
       "      <td>0.001791</td>\n",
       "      <td>0.000543</td>\n",
       "      <td>0.000060</td>\n",
       "      <td>0.989292</td>\n",
       "      <td>0.001043</td>\n",
       "      <td>0.006171</td>\n",
       "      <td>12955</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>12955 rows × 9 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "          prob0     prob1     prob2     prob3     prob4     prob5     prob6  \\\n",
       "0      0.012991  0.002973  0.116246  0.112650  0.000771  0.018385  0.008723   \n",
       "1      0.875510  0.000939  0.005767  0.006461  0.000534  0.053984  0.018161   \n",
       "2      0.998085  0.000038  0.000218  0.000072  0.000013  0.000740  0.000151   \n",
       "3      0.045739  0.001098  0.004962  0.198713  0.001311  0.132568  0.026041   \n",
       "4      0.989740  0.000035  0.001995  0.000887  0.000016  0.005407  0.000468   \n",
       "...         ...       ...       ...       ...       ...       ...       ...   \n",
       "12950  0.833071  0.003057  0.014412  0.003555  0.000654  0.034868  0.003584   \n",
       "12951  0.946363  0.000961  0.002724  0.002242  0.013856  0.023608  0.002090   \n",
       "12952  0.000735  0.000256  0.001295  0.000469  0.000031  0.973190  0.017754   \n",
       "12953  0.001971  0.000021  0.000765  0.000369  0.000025  0.994096  0.000372   \n",
       "12954  0.000976  0.000124  0.001791  0.000543  0.000060  0.989292  0.001043   \n",
       "\n",
       "          prob7  file_id  \n",
       "0      0.727260        1  \n",
       "1      0.038644        2  \n",
       "2      0.000684        3  \n",
       "3      0.589569        4  \n",
       "4      0.001452        5  \n",
       "...         ...      ...  \n",
       "12950  0.106798    12951  \n",
       "12951  0.008157    12952  \n",
       "12952  0.006271    12953  \n",
       "12953  0.002380    12954  \n",
       "12954  0.006171    12955  \n",
       "\n",
       "[12955 rows x 9 columns]"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "result=pd.DataFrame(result,columns=['prob0','prob1','prob2','prob3','prob4','prob5','prob6','prob7'])\n",
    "result['file_id']=df_test['file_id'].values\n",
    "result#根据预测的结果构建一个dataframe 并且把测试集对应的编号给加上去"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "#结果文件保存一下 并且调整一下索引  按照官方给的提交案列进行保存\n",
    "columns=['file_id','prob0','prob1','prob2','prob3','prob4','prob5','prob6','prob7']\n",
    "result.to_csv('./baseline_lgb_itr2000.csv',index=False,columns=columns)#可以在保存文件的时候调整一下ID"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>file_id</th>\n",
       "      <th>prob0</th>\n",
       "      <th>prob1</th>\n",
       "      <th>prob2</th>\n",
       "      <th>prob3</th>\n",
       "      <th>prob4</th>\n",
       "      <th>prob5</th>\n",
       "      <th>prob6</th>\n",
       "      <th>prob7</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>0.012991</td>\n",
       "      <td>0.002973</td>\n",
       "      <td>0.116246</td>\n",
       "      <td>0.112650</td>\n",
       "      <td>0.000771</td>\n",
       "      <td>0.018385</td>\n",
       "      <td>0.008723</td>\n",
       "      <td>0.727260</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>0.875510</td>\n",
       "      <td>0.000939</td>\n",
       "      <td>0.005767</td>\n",
       "      <td>0.006461</td>\n",
       "      <td>0.000534</td>\n",
       "      <td>0.053984</td>\n",
       "      <td>0.018161</td>\n",
       "      <td>0.038644</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>0.998085</td>\n",
       "      <td>0.000038</td>\n",
       "      <td>0.000218</td>\n",
       "      <td>0.000072</td>\n",
       "      <td>0.000013</td>\n",
       "      <td>0.000740</td>\n",
       "      <td>0.000151</td>\n",
       "      <td>0.000684</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>0.045739</td>\n",
       "      <td>0.001098</td>\n",
       "      <td>0.004962</td>\n",
       "      <td>0.198713</td>\n",
       "      <td>0.001311</td>\n",
       "      <td>0.132568</td>\n",
       "      <td>0.026041</td>\n",
       "      <td>0.589569</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>0.989740</td>\n",
       "      <td>0.000035</td>\n",
       "      <td>0.001995</td>\n",
       "      <td>0.000887</td>\n",
       "      <td>0.000016</td>\n",
       "      <td>0.005407</td>\n",
       "      <td>0.000468</td>\n",
       "      <td>0.001452</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12950</th>\n",
       "      <td>12951</td>\n",
       "      <td>0.833071</td>\n",
       "      <td>0.003057</td>\n",
       "      <td>0.014412</td>\n",
       "      <td>0.003555</td>\n",
       "      <td>0.000654</td>\n",
       "      <td>0.034868</td>\n",
       "      <td>0.003584</td>\n",
       "      <td>0.106798</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12951</th>\n",
       "      <td>12952</td>\n",
       "      <td>0.946363</td>\n",
       "      <td>0.000961</td>\n",
       "      <td>0.002724</td>\n",
       "      <td>0.002242</td>\n",
       "      <td>0.013856</td>\n",
       "      <td>0.023608</td>\n",
       "      <td>0.002090</td>\n",
       "      <td>0.008157</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12952</th>\n",
       "      <td>12953</td>\n",
       "      <td>0.000735</td>\n",
       "      <td>0.000256</td>\n",
       "      <td>0.001295</td>\n",
       "      <td>0.000469</td>\n",
       "      <td>0.000031</td>\n",
       "      <td>0.973190</td>\n",
       "      <td>0.017754</td>\n",
       "      <td>0.006271</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12953</th>\n",
       "      <td>12954</td>\n",
       "      <td>0.001971</td>\n",
       "      <td>0.000021</td>\n",
       "      <td>0.000765</td>\n",
       "      <td>0.000369</td>\n",
       "      <td>0.000025</td>\n",
       "      <td>0.994096</td>\n",
       "      <td>0.000372</td>\n",
       "      <td>0.002380</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12954</th>\n",
       "      <td>12955</td>\n",
       "      <td>0.000976</td>\n",
       "      <td>0.000124</td>\n",
       "      <td>0.001791</td>\n",
       "      <td>0.000543</td>\n",
       "      <td>0.000060</td>\n",
       "      <td>0.989292</td>\n",
       "      <td>0.001043</td>\n",
       "      <td>0.006171</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>12955 rows × 9 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "       file_id     prob0     prob1     prob2     prob3     prob4     prob5  \\\n",
       "0            1  0.012991  0.002973  0.116246  0.112650  0.000771  0.018385   \n",
       "1            2  0.875510  0.000939  0.005767  0.006461  0.000534  0.053984   \n",
       "2            3  0.998085  0.000038  0.000218  0.000072  0.000013  0.000740   \n",
       "3            4  0.045739  0.001098  0.004962  0.198713  0.001311  0.132568   \n",
       "4            5  0.989740  0.000035  0.001995  0.000887  0.000016  0.005407   \n",
       "...        ...       ...       ...       ...       ...       ...       ...   \n",
       "12950    12951  0.833071  0.003057  0.014412  0.003555  0.000654  0.034868   \n",
       "12951    12952  0.946363  0.000961  0.002724  0.002242  0.013856  0.023608   \n",
       "12952    12953  0.000735  0.000256  0.001295  0.000469  0.000031  0.973190   \n",
       "12953    12954  0.001971  0.000021  0.000765  0.000369  0.000025  0.994096   \n",
       "12954    12955  0.000976  0.000124  0.001791  0.000543  0.000060  0.989292   \n",
       "\n",
       "          prob6     prob7  \n",
       "0      0.008723  0.727260  \n",
       "1      0.018161  0.038644  \n",
       "2      0.000151  0.000684  \n",
       "3      0.026041  0.589569  \n",
       "4      0.000468  0.001452  \n",
       "...         ...       ...  \n",
       "12950  0.003584  0.106798  \n",
       "12951  0.002090  0.008157  \n",
       "12952  0.017754  0.006271  \n",
       "12953  0.000372  0.002380  \n",
       "12954  0.001043  0.006171  \n",
       "\n",
       "[12955 rows x 9 columns]"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#不放心的 话 可以读取进来看看试试\n",
    "pd.read_csv('./baseline_lgb_itr2000.csv')#已经得到了分数 其余的后面看改进吧！"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 再换一下xgb跑一下试试看"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "XGBClassifier(base_score=None, booster=None, colsample_bylevel=None,\n",
       "              colsample_bynode=None, colsample_bytree=0.8,\n",
       "              eval_metric='logloss', gamma=None, gpu_id=None,\n",
       "              importance_type='gain', interaction_constraints=None,\n",
       "              learning_rate=0.005, max_delta_step=None, max_depth=9,\n",
       "              min_child_samples=3, min_child_weight=None, missing=nan,\n",
       "              monotone_constraints=None, n_estimators=2000, n_jobs=None,\n",
       "              num_parallel_tree=None, objective='multi:softprob',\n",
       "              random_state=None, reg_alpha=None, reg_lambda=0.5,\n",
       "              scale_pos_weight=None, subsample=0.8, tree_method=None,\n",
       "              validate_parameters=None, verbosity=None)"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import xgboost as xgb\n",
    "xgb = xgb.XGBClassifier(\n",
    "            max_depth=9, learning_rate=0.005, n_estimators=2000, \n",
    "            objective='multi:softprob',  \n",
    "            subsample=0.8, colsample_bytree=0.8, \n",
    "            min_child_samples=3, eval_metric='logloss', reg_lambda=0.5)\n",
    "xgb"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[03:50:55] WARNING: ../src/learner.cc:516: \n",
      "Parameters: { min_child_samples } might not be used.\n",
      "\n",
      "  This may not be accurate due to some parameters are only used in language bindings but\n",
      "  passed down to XGBoost core.  Or some parameters are not used but slip through this\n",
      "  verification. Please open an issue if you find above cases.\n",
      "\n",
      "\n",
      "CPU times: user 1h 25min 34s, sys: 9min 10s, total: 1h 34min 45s\n",
      "Wall time: 3min 2s\n"
     ]
    }
   ],
   "source": [
    "%%time\n",
    "xgb.fit(df_train.drop('label',axis=1),df_train['label'])\n",
    "result_xgb=clf.predict_proba(df_test)\n",
    "result_xgb=pd.DataFrame(result,columns=['prob0','prob1','prob2','prob3','prob4','prob5','prob6','prob7'])\n",
    "result_xgb['file_id']=df_test['file_id'].values\n",
    "columns=['file_id','prob0','prob1','prob2','prob3','prob4','prob5','prob6','prob7']\n",
    "result.to_csv('./baseline_xgb_itr2000.csv',index=False,columns=columns)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
